package com.anfeng.cms.util.base;

import com.anfeng.cms.common.Common;
import com.anfeng.cms.domain.attendance.AfRosterDetail;
import com.anfeng.cms.domain.attendance.AfRosterInfo;
import com.anfeng.cms.domain.emp.AfEmployeeInfo;
import com.anfeng.cms.domain.org.AfDepartment;
import com.anfeng.cms.domain.org.AfJob;
import com.anfeng.cms.domain.org.AfPost;
import com.anfeng.cms.request.emp.AddEmployeeInfoDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * excel读写工具类
 */
@Slf4j
public class POIUtil {
    private final static String xls = "xls";
    private final static String xlsx = "xlsx";

    /**
     * 读取员工信息excel内容
     *
     * @param fileContent        内容
     * @param filePath           地址
     * @return
     * @throws IOException
     */
    public static Map<String, Object> readExcelEmployee(byte[] fileContent, String filePath) throws IOException {

        Map<String, Object> result = new HashMap<>();
        //List<AddCompanyPaymentErrorDetailDTO> addCompanyPaymentErrorDetailDTOS = new LinkedList<>();
        List<AfEmployeeInfo> employeeInfoDTOS = new ArrayList<>();

        //获得Workbook工作薄对象
        Workbook workbook = getWorkBook(fileContent, filePath);
        //创建返回对象，把每行中的值作为一个数组，所有行作为一个集合返回
        List<String[]> list = new ArrayList<String[]>();
        if (workbook != null) {
            //获得当前sheet工作表
            Sheet sheet = workbook.getSheetAt(0);
            //获得当前sheet的开始行
            int firstRowNum = sheet.getFirstRowNum();
            Row titleRow = sheet.getRow(firstRowNum);
            if (!isRowEmpty(titleRow)) {
                if (!getCellValue(titleRow.getCell(0)).equals("姓名")) {
                    throw new IOException("姓名 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(1)).equals("性别")) {
                    throw new IOException("性别 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(2)).equals("部门")) {
                    throw new IOException("部门 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(3)).equals("岗位")) {
                    throw new IOException("岗位 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(4)).equals("工种")) {
                    throw new IOException("工种 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(5)).equals("员工编号")) {
                    throw new IOException("员工编号 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(6)).equals("入职时间")) {
                    throw new IOException("入职时间 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(7)).equals("状态")) {
                    throw new IOException("状态 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(8)).equals("手机号")) {
                    throw new IOException("手机号 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(9)).equals("证件号")) {
                    throw new IOException("证件号 列标题不正确");
                }
            } else {
                throw new IOException();
            }

            //获得当前sheet的结束行
            int lastRowNum = sheet.getLastRowNum();
            //循环除了第一行的所有行
            for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) {
                //获得当前行
                Row row = sheet.getRow(rowNum);
                if (isRowEmpty(row)) {
                    continue;
                }
                AfEmployeeInfo addEmployeeInfoDTO = new AfEmployeeInfo();
                //AddCompanyPaymentErrorDetailDTO addCompanyPaymentErrorDetailDTO = new AddCompanyPaymentErrorDetailDTO();
                //循环当前行
                for (int cellNum = 0; cellNum < 10; cellNum++) {
                    Cell cell = row.getCell(cellNum);
                    if (getCellValue(titleRow.getCell(cellNum)).equals("姓名")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            addEmployeeInfoDTO.setName(cellValue.trim());
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("性别")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            String gender = cellValue.trim();
                            if ("男".equals(gender)) {
                                addEmployeeInfoDTO.setGender(Common.GENDER_MALE);
                            } else if ("女".equals(gender)) {
                                addEmployeeInfoDTO.setGender(Common.GENDER_FEMALE);
                            }
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("部门")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            addEmployeeInfoDTO.setDeptName(cellValue.trim());
                        } else {
                            // TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("岗位")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            addEmployeeInfoDTO.setPostName(cellValue.trim());
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("工种")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            addEmployeeInfoDTO.setJobName(cellValue.trim());
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("员工编号")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            addEmployeeInfoDTO.setEmpNo(cellValue.trim());
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("入职时间")) {
                        Date date = cell.getDateCellValue();
                        if (null != date) {
                            addEmployeeInfoDTO.setHireDate(date);
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("状态")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            if ("在职".equals(cellValue.trim())) {
                                addEmployeeInfoDTO.setStatus(Common.EMPLOYEE_STATUS_WORKING);
                            } else if("休假".equals(cellValue.trim())) {
                                addEmployeeInfoDTO.setStatus(Common.EMPLOYEE_STATUS_VOCATION);
                            } else if ("离职".equals(cellValue.trim())) {
                                addEmployeeInfoDTO.setStatus(Common.EMPLOYEE_STATUS_DIMISSION);
                            }
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("手机号")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            addEmployeeInfoDTO.setMobile(cellValue.trim());
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("证件号")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            addEmployeeInfoDTO.setIdentityNo(cellValue.trim());
                        } else {
                            //TODO
                        }
                    }
                }
                employeeInfoDTOS.add(addEmployeeInfoDTO);
            }
        }
        result.put("employeeInfos", employeeInfoDTOS);
        return result;
    }

    /**
     * 读取排班信息
     * @param fileContent 内容
     * @param filePath 文件
     * @return 读取信息
     */
    public static Map<String, Object> readExcelSchedule(byte[] fileContent, String filePath) throws Exception {
        Map<String, Object> result = new HashMap<>();
        List<AfRosterDetail> rosterDetails = new ArrayList<>();

        //获得Workbook工作薄对象
        Workbook workbook = getWorkBook(fileContent, filePath);
        //创建返回对象，把每行中的值作为一个数组，所有行作为一个集合返回
        List<String[]> list = new ArrayList<String[]>();
        if (workbook != null) {
            //获得当前sheet工作表
            Sheet sheet = workbook.getSheetAt(0);
            //获得当前sheet的开始行
            int firstRowNum = sheet.getFirstRowNum();
            Row titleRow = sheet.getRow(firstRowNum);
            if (!isRowEmpty(titleRow)) {
                if (!getCellValue(titleRow.getCell(0)).equals("姓名")) {
                    throw new IOException("姓名 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(1)).equals("部门")) {
                    throw new IOException("部门 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(2)).equals("工种")) {
                    throw new IOException("工种 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(3)).equals("员工编号")) {
                    throw new IOException("员工编号 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(4)).equals("手机号")) {
                    throw new IOException("手机号 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(5)).equals("类型")) {
                    throw new IOException("类型 列标题不正确");
                }
            } else {
                throw new IOException();
            }

            //获得当前sheet的结束行
            int lastRowNum = sheet.getLastRowNum();
            //循环除了第一行的所有行
            for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) {
                //获得当前行
                Row row = sheet.getRow(rowNum);
                if (isRowEmpty(row)) {
                    continue;
                }
                AfRosterDetail afRosterDetail = new AfRosterDetail();
                //AddCompanyPaymentErrorDetailDTO addCompanyPaymentErrorDetailDTO = new AddCompanyPaymentErrorDetailDTO();
                //循环当前行
                for (int cellNum = 0; cellNum < 6; cellNum++) {
                    Cell cell = row.getCell(cellNum);
                    if (getCellValue(titleRow.getCell(cellNum)).equals("姓名")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            afRosterDetail.setEmpName(cellValue.trim());
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("部门")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            afRosterDetail.setDeptName(cellValue.trim());
                        } else {
                            // TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("工种")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            afRosterDetail.setJobName(cellValue.trim());
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("员工编号")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            afRosterDetail.setEmpNo(cellValue.trim());
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("手机号")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            afRosterDetail.setEmpMobile(cellValue.trim());
                        } else {
                            //TODO
                        }
                    }  else if (getCellValue(titleRow.getCell(cellNum)).equals("类型")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            if ("长期".equals(cellValue.trim())) {
                                afRosterDetail.setRosterType(Common.ROSTER_TYPE_LONG_TERM);
                            } else if("临时".equals(cellValue.trim())) {
                                afRosterDetail.setRosterType(Common.ROSTER_TYPE_INTERIM);
                            }
                        } else {
                            //TODO
                        }
                    }
                }
                rosterDetails.add(afRosterDetail);
            }
        }
        result.put("rosterDetails", rosterDetails);
        return result;
    }

    /**
     * 导入班次信息
     * @param fileContent 数据
     * @param filePath 文件名
     * @return 数据信息
     * @throws Exception
     */
    public static Map<String, Object> readExcelSchClass(byte[] fileContent, String filePath) throws Exception {
        Map<String, Object> result = new HashMap<>();
        List<AfRosterInfo> rosterInfos = new ArrayList<>();

        //获得Workbook工作薄对象
        Workbook workbook = getWorkBook(fileContent, filePath);
        if (workbook != null) {
            //获得当前sheet工作表
            Sheet sheet = workbook.getSheetAt(0);
            //获得当前sheet的开始行
            int firstRowNum = sheet.getFirstRowNum();
            Row titleRow = sheet.getRow(firstRowNum);
            if (!isRowEmpty(titleRow)) {
                if (!getCellValue(titleRow.getCell(0)).equals("班次")) {
                    throw new IOException("班次 列标题不正确");
                }
                if (!getCellValue(titleRow.getCell(1)).equals("是否跨天")) {
                    throw new IOException("是否跨天 列标题不正确");
                }
            } else {
                throw new IOException();
            }

            //获得当前sheet的结束行
            int lastRowNum = sheet.getLastRowNum();
            //循环除了第一行的所有行
            for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) {
                //获得当前行
                Row row = sheet.getRow(rowNum);
                if (isRowEmpty(row)) {
                    continue;
                }
                AfRosterInfo afRoster = new AfRosterInfo();
                //AddCompanyPaymentErrorDetailDTO addCompanyPaymentErrorDetailDTO = new AddCompanyPaymentErrorDetailDTO();
                //循环当前行
                for (int cellNum = 0; cellNum < 2; cellNum++) {
                    Cell cell = row.getCell(cellNum);
                    if (getCellValue(titleRow.getCell(cellNum)).equals("班次")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            afRoster.setName(cellValue.trim());
                        } else {
                            //TODO
                        }
                    } else if (getCellValue(titleRow.getCell(cellNum)).equals("是否跨天")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            if ("跨天".equals(cellValue.trim())) {
                                afRoster.setCross(Common.ROSTER_CROSS_TYPE_OVERDAY);
                            } else if("当天".equals(cellValue.trim())) {
                                afRoster.setCross(Common.ROSTER_CROSS_TYPE_ONEDAY);
                            }
                        } else {
                            //TODO
                        }
                    }
                }
                rosterInfos.add(afRoster);
            }
        }
        result.put("rosters", rosterInfos);
        return result;
    }

    /**
     * 导入部门
     * @param fileContent 文件数据
     * @param filePath 名称
     * @return 数据
     * @throws Exception
     */
    public static Map<String, Object> readExcelDepart(byte[] fileContent, String filePath) throws Exception {
        Map<String, Object> result = new HashMap<>();
        List<AfDepartment> departmentList = new ArrayList<>();

        //获得Workbook工作薄对象
        Workbook workbook = getWorkBook(fileContent, filePath);
        if (workbook != null) {
            //获得当前sheet工作表
            Sheet sheet = workbook.getSheetAt(0);
            //获得当前sheet的开始行
            int firstRowNum = sheet.getFirstRowNum();
            Row titleRow = sheet.getRow(firstRowNum);
            if (!isRowEmpty(titleRow)) {
                if (!getCellValue(titleRow.getCell(0)).equals("部门")) {
                    throw new IOException("部门 列标题不正确");
                }
            } else {
                throw new IOException();
            }

            //获得当前sheet的结束行
            int lastRowNum = sheet.getLastRowNum();
            //循环除了第一行的所有行
            for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) {
                //获得当前行
                Row row = sheet.getRow(rowNum);
                if (isRowEmpty(row)) {
                    continue;
                }
                AfDepartment afDepartment = new AfDepartment();
                //AddCompanyPaymentErrorDetailDTO addCompanyPaymentErrorDetailDTO = new AddCompanyPaymentErrorDetailDTO();
                //循环当前行
                for (int cellNum = 0; cellNum < 1; cellNum++) {
                    Cell cell = row.getCell(cellNum);
                    if (getCellValue(titleRow.getCell(cellNum)).equals("部门")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            afDepartment.setRemark(cellValue.trim());
                        } else {
                            //TODO
                        }
                    }
                }
                departmentList.add(afDepartment);
            }
        }
        result.put("departments", departmentList);
        return result;
    }

    /**
     * 导入岗位信息
     * @param fileContent 数据
     * @param filePath 文件名
     * @return 数据
     * @throws Exception
     */
    public static Map<String, Object> readExcelPost(byte[] fileContent, String filePath) throws Exception {
        Map<String, Object> result = new HashMap<>();
        List<AfPost> postList = new ArrayList<>();

        //获得Workbook工作薄对象
        Workbook workbook = getWorkBook(fileContent, filePath);
        if (workbook != null) {
            //获得当前sheet工作表
            Sheet sheet = workbook.getSheetAt(0);
            //获得当前sheet的开始行
            int firstRowNum = sheet.getFirstRowNum();
            Row titleRow = sheet.getRow(firstRowNum);
            if (!isRowEmpty(titleRow)) {
                if (!getCellValue(titleRow.getCell(0)).equals("岗位")) {
                    throw new IOException("岗位 列标题不正确");
                }
            } else {
                throw new IOException();
            }

            //获得当前sheet的结束行
            int lastRowNum = sheet.getLastRowNum();
            //循环除了第一行的所有行
            for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) {
                //获得当前行
                Row row = sheet.getRow(rowNum);
                if (isRowEmpty(row)) {
                    continue;
                }
                AfPost afPost = new AfPost();
                //AddCompanyPaymentErrorDetailDTO addCompanyPaymentErrorDetailDTO = new AddCompanyPaymentErrorDetailDTO();
                //循环当前行
                for (int cellNum = 0; cellNum < 1; cellNum++) {
                    Cell cell = row.getCell(cellNum);
                    if (getCellValue(titleRow.getCell(cellNum)).equals("岗位")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            afPost.setName(cellValue.trim());
                        } else {
                            //TODO
                        }
                    }
                }
                postList.add(afPost);
            }
        }
        result.put("posts", postList);
        return result;
    }

    /**
     * 导入工种信息
     * @param fileContent 数据流
     * @param filePath 文件名
     * @return 信息
     * @throws Exception
     */
    public static Map<String, Object> readExcelJob(byte[] fileContent, String filePath) throws Exception {
        Map<String, Object> result = new HashMap<>();
        List<AfJob> jobList = new ArrayList<>();

        //获得Workbook工作薄对象
        Workbook workbook = getWorkBook(fileContent, filePath);
        if (workbook != null) {
            //获得当前sheet工作表
            Sheet sheet = workbook.getSheetAt(0);
            //获得当前sheet的开始行
            int firstRowNum = sheet.getFirstRowNum();
            Row titleRow = sheet.getRow(firstRowNum);
            if (!isRowEmpty(titleRow)) {
                if (!getCellValue(titleRow.getCell(0)).equals("工种")) {
                    throw new IOException("工种 列标题不正确");
                }
            } else {
                throw new IOException();
            }
            //获得当前sheet的结束行
            int lastRowNum = sheet.getLastRowNum();
            //循环除了第一行的所有行
            for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) {
                //获得当前行
                Row row = sheet.getRow(rowNum);
                if (isRowEmpty(row)) {
                    continue;
                }
                AfJob afJob = new AfJob();
                //循环当前行
                for (int cellNum = 0; cellNum < 1; cellNum++) {
                    Cell cell = row.getCell(cellNum);
                    if (getCellValue(titleRow.getCell(cellNum)).equals("工种")) {
                        String cellValue = getCellValue(cell);
                        if (StringUtils.isNotBlank(cellValue)) {
                            afJob.setName(cellValue.trim());
                        } else {
                            //TODO
                        }
                    }
                }
                jobList.add(afJob);
            }
        }
        result.put("jobs", jobList);
        return result;
    }

    private static void checkFile(MultipartFile file) throws IOException {
        //判断文件是否存在  
        if (null == file) {
            log.error("文件不存在！");
            throw new FileNotFoundException("文件不存在！");
        }
        //获得文件名  
        String fileName = file.getOriginalFilename();
        //判断文件是否是excel文件  
        if (!fileName.endsWith(xls) && !fileName.endsWith(xlsx)) {
            log.error(fileName + "不是excel文件");
            throw new IOException(fileName + "不是excel文件");
        }
    }

    private static Workbook getWorkBook(MultipartFile file) {
        //获得文件名  
        String fileName = file.getOriginalFilename();
        //创建Workbook工作薄对象，表示整个excel  
        Workbook workbook = null;
        try {
            //获取excel文件的io流  
            InputStream is = file.getInputStream();
            //根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象  
            if (fileName.endsWith(xls)) {
                //2003  
                workbook = new HSSFWorkbook(is);
            } else if (fileName.endsWith(xlsx)) {
                //2007  
                workbook = new XSSFWorkbook(is);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return workbook;
    }

    private static Workbook getWorkBook(byte[] fileContent, String filePath) {
        InputStream input = new ByteArrayInputStream(fileContent);
        //获得文件名
        //创建Workbook工作薄对象，表示整个excel
        Workbook workbook = null;
        try {
            //获取excel文件的io流
            InputStream is = input;
            //根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象
            if (filePath.endsWith(xls)) {
                //2003
                workbook = new HSSFWorkbook(is);
            } else if (filePath.endsWith(xlsx)) {
                //2007
                workbook = new XSSFWorkbook(is);
            }
        } catch (IOException e) {
            log.info(e.getMessage());
        }
        return workbook;
    }

    private static String getCellValue(Cell cell) {
        String cellValue = "";
        if (cell == null) {
            return cellValue;
        }
        //把数字当成String来读，避免出现1读成1.0的情况  
        if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
            cell.setCellType(Cell.CELL_TYPE_STRING);
        }
        //判断数据的类型  
        switch (cell.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC: //数字
                cellValue = String.valueOf(cell.getNumericCellValue());
                break;
            case Cell.CELL_TYPE_STRING: //字符串
                cellValue = String.valueOf(cell.getStringCellValue());
                break;
            case Cell.CELL_TYPE_BOOLEAN: //Boolean
                cellValue = String.valueOf(cell.getBooleanCellValue());
                break;
            case Cell.CELL_TYPE_FORMULA: //公式
                cellValue = String.valueOf(cell.getCellFormula());
                break;
            case Cell.CELL_TYPE_BLANK: //空值
                cellValue = "";
                break;
            case Cell.CELL_TYPE_ERROR: //故障
                cellValue = "非法字符";
                break;
            default:
                cellValue = "未知类型";
                break;
        }
        return cellValue;
    }

    //判断行为空
    private static boolean isRowEmpty(Row row) {
        if (row == null) {
            return true;
        }
        for (int c = row.getFirstCellNum(); c < row.getLastCellNum(); c++) {
            Cell cell = row.getCell(c);
            if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
                return false;
            }

        }
        return true;
    }
}